import datetime

from pydantic import BaseModel, Field
from typing import Optional, List, Union


class DriverModel(BaseModel):
    id: Optional[int] = Field(None, primary_key=True)
    driver_id: Optional[str] = Field(None, comment='驾驶员编码')
    driver_name: Optional[str] = Field(None, comment='驾驶员姓名')
    driver_model_list: Optional[List] = Field(None, comment='准驾车型集合')
    phone: Optional[str] = Field(None, comment='手机号')
    identity_card: Optional[str] = Field(None, comment='身份证号')
    state: Optional[int] = Field(None, comment='状态（0 失效，1 有效）')
    create_time: Optional[datetime.datetime] = Field(None, comment='创建时间')
    experation_begin: Optional[datetime.datetime] = Field(None, comment='驾照有效期开始时间')
    experation_end: Optional[datetime.datetime] = Field(None, comment='驾照有效期结束时间')
    certificate_no: Optional[str] = Field(None, comment='从业资格证号')
    certificate_image: Optional[str] = Field(None, comment='从业资格证图片')
    create_by: Optional[str] = Field(None, comment='创建人')
    update_time: Optional[datetime.datetime] = Field(None, comment='修改时间')
    update_by: Optional[str] = Field(None, comment='修改人')
    car_team_id: Optional[Optional[str]] = Field(None, comment='所属车队id')
    account: Optional[Optional[str]] = Field(None, comment='登陆账号')
    password: Optional[Optional[str]] = Field(None, comment='密码')

class DriverModelFree(BaseModel):
    id: Optional[int] = Field(None, primary_key=True)
    driver_id: Optional[str] = Field(None, comment='驾驶员编码')
    driver_name: Optional[str] = Field(None, comment='驾驶员姓名')
    driver_model_list: Optional[List] = Field(None, comment='准驾车型集合')
    phone: Optional[str] = Field(None, comment='手机号')
    identity_card: Optional[str] = Field(None, comment='身份证号')
    state: Optional[int] = Field(None, comment='状态（0 失效，1 有效）')
    create_time: Optional[datetime.datetime] = Field(None, comment='创建时间')
    experation_begin: Optional[datetime.datetime] = Field(None, comment='驾照有效期开始时间')
    experation_end: Optional[datetime.datetime] = Field(None, comment='驾照有效期结束时间')
    certificate_no: Optional[str] = Field(None, comment='从业资格证号')
    certificate_image: Optional[str] = Field(None, comment='从业资格证图片')
    create_by: Optional[str] = Field(None, comment='创建人')
    update_time: Optional[datetime.datetime] = Field(None, comment='修改时间')
    update_by: Optional[str] = Field(None, comment='修改人')
    car_team_id: Optional[Optional[str]] = Field(None, comment='所属车队id')
    account: Optional[Optional[str]] = Field(None, comment='登陆账号')
    password: Optional[Optional[str]] = Field(None, comment='密码')
    driver_state: Optional[Optional[str]] = Field(None, comment='司机状态 空闲 任务中')


class DriverForQuery(BaseModel):
    driver_name: Optional[str] = Field(None, title="驾驶员姓名")
    driver_id: Optional[str] = Field(None, title="人员编号")
    phone: Optional[str] = Field(None, title="手机号")


class DriverPageObject(DriverForQuery):
    page_num: int
    page_size: int


class CrudDriverResponse(BaseModel):
    is_success: bool
    message: str


class OrderListForQuery(BaseModel):
    start_time: Optional[datetime.datetime] = Field(None, comment='开始时间')
    end_time: Optional[datetime.datetime] = Field(None, comment='结束时间')

class OrderListForQueryAfter(BaseModel):
    query_begin: Optional[datetime.datetime] = Field(None, comment='查询开始时间 前端无需传入')
    query_end: Optional[datetime.datetime] = Field(None, comment='查询结束时间 前端无需传入')
    driver_id: Optional[str] = Field(None, comment='司机id')
    car_id: Optional[str] = Field(None, comment='车辆id')

class OrderListOrderChild(BaseModel):
    order_id: Optional[str] = Field(None, comment='用车申请id')
    confirm_time: Optional[datetime.datetime] = Field(None, comment='确认任务时间')
    reality_begin_time: Optional[datetime.datetime] = Field(None, comment='开始任务时间')
    reality_end_time: Optional[datetime.datetime] = Field(None, comment='结束任务时间')
class DriverOrderList(BaseModel):
    id: Optional[int] = Field(None, primary_key=True)
    driver_id: Optional[str] = Field(None, comment='驾驶员编码')
    driver_name: Optional[str] = Field(None, comment='驾驶员姓名')
    order_list: Optional[List[Union[OrderListOrderChild, None]]] = Field(None, comment='用车申请集合')

class DriverSimpleModel(BaseModel):
    id: Optional[int] = Field(None, primary_key=True)
    driver_id: Optional[str] = Field(None, comment='驾驶员编码')
    driver_name: Optional[str] = Field(None, comment='驾驶员姓名')
    car_department_name: Optional[str] = Field(None, comment='所属部门')
    driver_model: Optional[str] = Field(None, comment='准驾车型集合')
    phone: Optional[str] = Field(None, comment='手机号')

